package com.bschlearn.group.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bschlearn.group.common.util.JwtUtil;
import com.bschlearn.group.message.BaseReq;
import com.bschlearn.group.message.BaseRsp;
import com.bschlearn.group.message.group.GroupReq;
import com.bschlearn.group.model.User;
import com.bschlearn.group.service.groupservice.GetGroupListService;
import com.bschlearn.group.service.groupservice.GetGroupNameByIdService;

/**
 * 
 * @ClassName: GroupController 
 * @Description: TODO(分组controller) 
 * @author dcc
 * @date 2019年10月31日 下午3:28:00 
 * @CrossOrigin  解决跨域，*表示所有请求都可以访问
 *
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController()
@RequestMapping("/group")
public class GroupController {
	
	@Autowired
	private GetGroupListService getGroupListService;
	
	@Autowired
	private GetGroupNameByIdService getGroupNameByIdService;
	
	@RequestMapping("/getGroupList")
	public BaseRsp getGroupList(BaseReq req) throws Exception {
		return getGroupListService.service(req);
	}
	
	@RequestMapping("getGroupNameById")
	public BaseRsp getGroupNameById(GroupReq req) throws Exception {
		return getGroupNameByIdService.service(req);
	}
	
	@RequestMapping("/getJWT")
	public BaseRsp getJWT(BaseReq req) throws Exception {
		return BaseRsp.ok(JwtUtil.inst().createJWT(10000, new User(), 2000000));
	}
	
	@RequestMapping("/getUser")
	public BaseRsp getUser(BaseReq req) throws Exception {
		User user = (User)req.getRequest().getSession().getAttribute("user");
		return BaseRsp.ok(user);
	}
	
}
